﻿using System;
using System.Runtime.Serialization;

namespace Notoric.Model.Packaging
{
    /// <summary>
    /// The exception that is thrown when an error occurs during the serialization or deserialization of the project from an archive.
    /// </summary>
    /// <remarks>
    /// This exception may or may not include the string content of the XML element where the (de)serialization
    /// process failed. This string is stored in the <see cref="Exception.Data"/> collection under the <i>"Element"</i> key.
    /// </remarks>
    public class SerializationException : SystemException
    {
        /// <summary>
        /// Creates a new <see cref="SerializationException"/> instance.
        /// </summary>
        public SerializationException()
        {
        }

        /// <summary>
        /// Creates a new <see cref="SerializationException"/> instance.
        /// </summary>
        /// <param name="message">The message that describes the error.</param>
        /// <param name="elementContent">The content of the XML element where the (de)serialization failed</param>
        public SerializationException(string message, string elementContent)
            : base(message)
        {
            Data["Element"] = elementContent;
        }

        /// <summary>
        /// Creates a new <see cref="SerializationException"/> instance.
        /// </summary>
        /// <param name="message">The message that describes the error.</param>
        /// <param name="elementContent">The content of the XML element where the (de)serialization failed</param>
        /// <param name="innerException">The exception that is the cause of the current exception, or <see langword="null"/> if no inner exception is specified.</param>
        public SerializationException(string message, string elementContent, Exception innerException)
            : base(message, innerException)
        {
            Data["Element"] = elementContent;
        }

        /// <summary>
        /// Creates a new <see cref="SerializationException"/> instance.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        protected SerializationException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
    }
}
